import Vue from "vue";
import App from "./App";
import router from "./router";
import ElementUI from "element-ui";
import "@/assets/css/common.less";
import "@/assets/css/variable.less";
import "@/assets/css/theme/459f75/index.css";
// import 'element-ui/lib/theme-chalk/index.css';
import axios from "axios";
import echarts from "echarts";
import store from "./store";

Vue.config.productionTip = false;
Vue.use(ElementUI, { size: "medium" });
Vue.prototype.$axios = axios; // axios不能使用use
Vue.prototype.$echarts = echarts;

// 使用router.beforeEach注册一个全局前置守卫，对路由进行权限跳转
router.beforeEach((to, from, next) => {
  // 未匹配到路由时 跳转到error页面
  if (0 === to.matched.length) {
    next("/error");
    return false;
  }

  const role = localStorage.getItem("token");
  if (!role && to.path !== "/login") {
    next("/login");
  } else {
    next();
  }
});

new Vue({
  el: "#app",
  router,
  components: { App },
  store,
  template: "<App/>"
});
